import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'
import { useUserStore } from './stores/user'

const app = createApp(App)
const pinia = createPinia()

app.use(pinia)
app.use(router)

// 在应用挂载前初始化用户状态
const initializeApp = async () => {
  try {
    // 确保Pinia已经被安装
    await new Promise(resolve => setTimeout(resolve, 100))
    
    // 初始化用户状态
    const userStore = useUserStore()
    userStore.loadFromLocalStorage()
  } catch (error) {
    console.error('应用初始化错误:', error)
  } finally {
    // 挂载应用
    app.mount('#app')
  }
}

// 启动应用
initializeApp()
